{{ $str := "" }}
<div class="post-nav prev-next-pages col-12">
  <div class="row">
    <div class="post-nav-item col-6">
      {{if .NextInSection}}
      {{/* For the docs layout, prev/next labels are reversed. */}}
      {{ if eq .Type "docs" }}{{ $str = "previous" }}{{else}}{{ $str = "next" }}{{end}}
        <div class="meta-nav">{{ i18n $str }}</div>
        <a href="{{.NextInSection.RelPermalink}}" rel="next">{{.NextInSection.Title}}</a>
      {{else}}
        {{if not .IsSection}}
          {{if eq .Type "docs" }}{{ $str = "previous" }}{{else}}{{ $str = "next" }}{{end}}
          {{with .Page.Parent}}
            <div class="meta-nav">{{ i18n $str }}</div>
            <a href="{{.RelPermalink}}" rel="next">{{.Title}}</a>
          {{end}}
        {{end}}
      {{end}}
    </div>

    <div class="post-nav-item col-6 align-self-end">
      {{if .PrevInSection}}
      {{ if eq .Type "docs" }}{{ $str = "next" }}{{else}}{{ $str = "previous" }}{{end}}
        <div class="meta-nav">{{ i18n $str }}</div>
        <a href="{{.PrevInSection.RelPermalink}}" rel="prev">{{.PrevInSection.Title}}</a>
      {{else}}
        {{if and (eq .Type "docs") .IsSection}}
          {{ $parentName := .Params.Menu.docs.parent }}
          {{ $nextPage := "null" }}
          {{ $docPages := where site.RegularPages ".Type" "docs" }}
          {{ range $key, $page := $docPages }}
            {{ if and (eq $nextPage "null") (eq .Params.Menu.docs.parent $parentName) }}
              {{ $nextPage = $page }}
            {{ end }}
          {{ end }}
          {{ if not (eq $nextPage "null") }}
            {{ if eq .Type "docs" }}{{ $str = "next" }}{{else}}{{ $str = "previous" }}{{end}}
              <div class="meta-nav">{{ i18n $str }}</div>
              <a href="{{$nextPage.RelPermalink}}" rel="prev">{{$nextPage.Title}}</a>
          {{ end }}
        {{end}}
      {{end}}
    </div>
  </div>
</div>
